# -*- coding: utf-8 -*- 
# @Time : 2023/11/23 10:25 
# @Author : YangGuangjian
# @File : demo.py

import json
from jsonpath_ng import parse

ddd = {
    "args": {},
    "data": "{\"srid\": \"123456\", \"signKey\": \"asdfqwer\"}",
    "files": {},
    "form": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Content-Length": "41",
        "Host": "httpbin.org",
        "User-Agent": "python-requests/2.27.1",
        "X-Amzn-Trace-Id": "Root=1-656706ce-481ef2a8217e03ca557b8515"
    },
    "json": {
        "signKey": "asdfqwer",
        "srid": "123456"
    },
    "origin": "124.64.17.141",
    "url": "http://httpbin.org/post"
}

def _save_mid_vars(data: dict, j_path: str):
    try:
        contents = [match.value for match in parse(j_path).find(data)]
        return contents
    except json.JSONDecodeError:
        return None

# 示例 JSONPath: $.data.srid
res = _save_mid_vars(ddd, "$.data.srid")

print(res)
